package com.mmy.controller.report;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.mmy.controller.Common;
import com.mmy.service.report.ReportService;

@Controller
public class ReportController {
	
	private static Logger logger = LoggerFactory.getLogger(ReportController.class);
	
	@Autowired
	private ReportService reportService;
	@Autowired
	private Common common;
	
	/**
	 * 函数功能说明： 跳转--日报
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @author 创建人 liys
	 * @date 创建日期 2021-04-16
	 */
	@RequestMapping("/dailyreport")
	public String daily(Model model) {
		List<Integer> num = reportService.getDailyTable();
		List<String> href = common.getChartHref();
		List<String> name = common.getChartList();
		List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < num.size(); i++) {
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("num", num.get(i));
			map.put("href", href.get(i));
			res.add(map);
		}
		model.addAttribute("name",name);
		model.addAttribute("res",res);
		return "report/reportDaily";
	}
	
	@RequestMapping("/dailyJson")
	@ResponseBody
	public String dailyJson() {
		
		List<Integer> num = reportService.getDailyTable();
		List<String> name = common.getChartList();
		Map<String,Object> res = new HashMap<String,Object>();
		res.put("num",num);
		res.put("name", name);
		return JSONObject.toJSONString(res);
	}
	
	/**
	 * 函数功能说明： 跳转--周报
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @author 创建人 liys
	 * @date 创建日期 2021-04-16
	 */
	@RequestMapping("/weeklyreport")
	public String weekly(Model model) {
		List<Integer> num = reportService.getWeeklyTable();
		List<String> href = common.getChartHref();
		List<String> name = common.getChartList();
		List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < num.size(); i++) {
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("num", num.get(i));
			map.put("href", href.get(i));
			res.add(map);
		}
		model.addAttribute("name",name);
		model.addAttribute("res",res);
		return "report/reportWeekly";
	}
	
	@RequestMapping("/weeklyJson")
	@ResponseBody
	public String weeklyJson() {
		
		List<Integer> num = reportService.getWeeklyTable();
		List<String> name = common.getChartList();
		Map<String,Object> res = new HashMap<String,Object>();
		res.put("num",num);
		res.put("name", name);
		return JSONObject.toJSONString(res);
	}
	/**
	 * 函数功能说明： 跳转--月报
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @author 创建人 liys
	 * @date 创建日期 2021-04-16
	 */
	@RequestMapping("/monthlyreport")
	public String monthly(Model model) {
		List<Integer> num = reportService.getMonthlyTable();
		List<String> href = common.getChartHref();
		List<String> name = common.getChartList();
		List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < num.size(); i++) {
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("num", num.get(i));
			map.put("href", href.get(i));
			res.add(map);
		}
		model.addAttribute("name",name);
		model.addAttribute("res",res);
		return "report/reportMonthly";
	}
	
	@RequestMapping("/monthlyJson")
	@ResponseBody
	public String monthlyJson() {
		
		List<Integer> num = reportService.getMonthlyTable();
		List<String> name = common.getChartList();
		Map<String,Object> res = new HashMap<String,Object>();
		res.put("num",num);
		res.put("name", name);
		return JSONObject.toJSONString(res);
	}
	
	/**
	 * 函数功能说明： 跳转--年报
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @author 创建人 liys
	 * @date 创建日期 2021-04-16
	 */
	@RequestMapping("/yearlyreport")
	public String yearly(Model model) {
		List<Integer> num = reportService.getYearlyTable();
		List<String> href = common.getChartHref();
		List<String> name = common.getChartList();
		List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
		for (int i = 0; i < num.size(); i++) {
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("num", num.get(i));
			map.put("href", href.get(i));
			res.add(map);
		}
		model.addAttribute("name",name);
		model.addAttribute("res",res);
		return "report/reportYearly";
	}
	
	@RequestMapping("/yearlyJson")
	@ResponseBody
	public String yearlyJson() {
		
		List<Integer> num = reportService.getYearlyTable();
		List<String> name = common.getChartList();
		Map<String,Object> res = new HashMap<String,Object>();
		res.put("num",num);
		res.put("name", name);
		return JSONObject.toJSONString(res);
	}
	
}
